

'''
一个1-n的排列,最少几次交换使得其为顺序
重在找循环节
'''
def minSwapSteps(arr):
    ans = 0
    ll = len(arr)
    mp = dict()
    for i in range(ll):
        mp[arr[i]] = i
    loops = 0
    f = [0] * ll
    for i in range(ll):
        if not f[i]:
            j = i
            while not f[j]:
                f[j] = 1
                j = mp[arr[j]]
            loops += 1

    ans += ll - loops
